package util.validate
{
	import mx.validators.ValidationResult;
	import mx.validators.Validator;
	
	
	public class RePasswordValidator extends Validator {
		
		// Define Array for the return value of doValidation().
		private var results:Array;
		
		private var password : String;
		
		// Constructor.
		public function RePasswordValidator() {
			// Call base class constructor. 
			super();
		}
		
		// 设置要比较的密码
		public function set Password(s : String):void
		{
			password = s;
		}
		
		// Define the doValidation() method.
		override protected function doValidation(value:Object):Array {
			
			// Convert value to a Number.
			var inputValue:String = String(value);
			
			// Clear results Array.
			results = [];
			
			// Call base class doValidation().
			results = super.doValidation(value);        
			// Return if there are errors.
			if (results.length > 0)
				return results;
			
			// If input value is not a number, or contains no value, 
			// issue a validation error.
			if (inputValue=="" || !value )
			{
				results.push(new ValidationResult(true, null, "NaN", 
					"请输入确认密码"));
				return results;
			}       
			
			// If calculated age is less than 18, issue a validation error.
			/*if ((inputValue.length) > 12) {
				results.push(new ValidationResult(true, null, "太长了", 
					"帐号要小于十二位."));
				return results;
			}*/
			if (inputValue!= password) {
				results.push(new ValidationResult(true, null, "输入错误", 
					"与第一次输入不相符"));
				return results;
			}
			return results;
		}
	}
}